package com.zjj.lbw.ai.old.function;

import java.time.LocalDateTime;
import java.util.Objects;
import java.util.function.Function;

import org.springframework.context.annotation.Description;
import org.springframework.stereotype.Component;
import io.swagger.v3.oas.annotations.media.Schema;

@Component
@Description("获取指定地点的当前时间")
public class DateService implements Function<DateService.Request, DateService.Response> {

    // 替换 Request record
    public static final class Request {
        private final @Schema(description = "地点") String address;

        public Request(String address) {
            this.address = address;
        }

        public String address() {
            return address;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Request request = (Request) o;
            return Objects.equals(address, request.address);
        }

        @Override
        public int hashCode() {
            return Objects.hash(address);
        }

        @Override
        public String toString() {
            return "Request{" + "address='" + address + '\'' + '}';
        }
    }

    // 替换 Response record
    public static final class Response {
        private final String date;

        public Response(String date) {
            this.date = date;
        }

        public String date() {
            return date;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Response response = (Response) o;
            return Objects.equals(date, response.date);
        }

        @Override
        public int hashCode() {
            return Objects.hash(date);
        }

        @Override
        public String toString() {
            return "Response{" + "date='" + date + '\'' + '}';
        }
    }

    @Override
    public Response apply(Request request) {
        System.out.println(request.address());
        return new Response(String.format("%s的当前时间是%s", request.address(), LocalDateTime.now()));
    }

}